﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace PersonalFinances.Models
{
    public class Account
    {
        #region Attributes and Properties

        private int _id;
        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private float _balance;
        public float Balance
        {
            get { return _balance; }
            set { _balance = value; }
        }

        #endregion

        #region Public Methods

        public void ApplyTransaction(Transaction transaction)
        {
            if (transaction.Paid)
                this._balance += transaction.Type == TransactionType.Credit ? transaction.Value : -transaction.Value;
        }

        public void CancelTransaction(Transaction transaction)
        {
            if (transaction.Paid)
                this._balance += transaction.Type == TransactionType.Credit ? -transaction.Value : +transaction.Value;
        }

        #endregion

        #region Overriden Methods

        public override string ToString()
        {
            return _name;
        }

        #endregion
    }

    public class AccountDbContext : DbContext
    {
        public AccountDbContext()
            : base("PersonalFinancesDbContext")
        {
        }

        public DbSet<Account> Accounts { get; set; }
    }
}